Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parsec

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parsec

  • 1.5.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NPM Version Downloads Build Status

Features | Install | Usage | Examples

About

Parsec is a tiny CLI parser.

Features

  • Default shorthands
  • Default values / types
  • Handle --no-* options
  • Handle unknown options

Install

npm install parsec

Usage

// ./index.js -par5ec
parse()
{
  "p": true,
  "a": true,
  "r": "5ec"
}

Customize:

// ./index.js -s42
parse("secret", ["verbose", "V", { default: true }])
{
  "s": 42,
  "secret": 42,
  "V": true,
  "verbose": true
}

Usage

Parse process.argv by default.

import parse from "parsec"
parse(alias1, alias2, ...)
  • Custom aliases
// ./index.js --bar
parse(["foo", "bar", "baz"])
{
  "foo": true,
  "bar": true,
  "baz": true
}
  • Example aliases
"foo" // → ["f", "foo"]
["F", "f", "foo"]
["foo", { default: "./" }]
["baz", { default: true }]
  • Default shorthands
// ./index.js -fb
parse("foo", "bar")
{
  "f": true,
  "foo": true,
  "b": true,
  "bar": true,
}
  • Default values and types
// ./index.js --file
parse(["f", "file", { default: "." }])
{
  "f": ".",
  "file": "."
}
  • Handle --no-flags
// ./index.js --no-foo --no-bar=baz
parse()
{
  "foo": false,
  "no-bar": "baz"
}
  • Handle unknown options
// ./index.js --bar
parse("foo", (option) => {
  throw new RangeError(`unknown option ${option}`) // bar
})
  • Bare operands and arguments after -- are added to ._. To override:
parse(["_", "alias"])
  • Bind parse to a different source of arguments:
parse.call(["--foo", "--bar"], [alias1, alias2, ...])

Examples

// ./node index.js -f bar -bp
parse()
{
  "f": "bar",
  "b": true,
  "p": "./"
}

with custom aliases:

parse("foo", "bar", ["path", { default: "./" }])
{
  "f": "bar",
  "foo": "bar",
  "b": true,
  "bar": true,
  "p": "./",
  "path": "./"
}

Keywords

FAQs

Package last updated on 09 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc